﻿using System;
using System.Data.OleDb;
using System.Windows.Forms;

namespace Texpro
{

    public class m_combo_item
    {
        private String var_code;
        private String var_text;

        public String combo_code
        {
            get { return var_code; }
            set { var_code = value; }
        }

        public String combo_text
        {
            get { return var_text; }
            set { var_text = value; }
        }

    }

    public static class PCPUB
    {

        public static string mc_app_product;
        public static string mc_app_version;
        public static string mc_app_build;
        //
        public static string mc_lic_key;
        public static string mc_lic_from;
        public static string mc_lic_upto;
        public static string mc_lic_cals;
        //
        public static string mc_org_name;
        public static string mc_org_address1;
        public static string mc_org_address2;
        public static string mc_org_address3;
        public static string mc_org_city;
        public static string mc_org_state;
        public static string mc_org_country;
        public static string mc_org_pincode;
        public static string mc_org_mobile1;
        public static string mc_org_mobile2;
        public static string mc_org_phone1;
        public static string mc_org_phone2;
        public static string mc_org_fax;
        public static string mc_org_email;
        public static string mc_org_website;
        //
        public static string m_db_provider;
        public static string m_db_server;
        public static string m_db_name;
        public static string m_db_user;
        public static string m_db_password;
        public static string m_oledb_connection;
        public static string m_sqldb_connection;
        //
        public static int m_mdi_child_top;
        public static int m_mdi_child_left;
        public static int m_mdi_child_height;
        public static int m_mdi_child_width;
        //
        public static string m_entry_form_mode;
        //
        public static string m_server_datetime;
        public static string m_form_option_code;
        public static string m_form_id;
        public static DateTime m_tran_date;
        public static string m_record_id;
        public static string m_record_date;
        public static string m_record_status;
        //
        public static string m_user_id;
        public static string m_user_name;
        public static string m_user_role_id;
        public static string m_user_role_name;
        public static bool   m_user_logged_in;
        //
        public static string m_popup_search_type;
        public static string m_popup_search_text;
        public static string m_popup_result_text;
        //
        public static string m_yarn_purchase_iw_id;
        public static string m_yarn_sales_ow_id;
        public static string m_yarn_material_iw_id;
        public static string m_dyeing_ow_id;
        public static string m_dyeing_iw_id;
        public static string m_weaving_ow_id;
        public static string m_weaving_iw_id;
        public static string m_weaving_adj_id;
        public static string m_washing_ow_id;
        public static string m_washing_iw_id;
        public static string m_tailoring_ow_id;
        public static string m_tailoring_iw_id;
        //
        public static string m_payment_id;
        public static string m_receipt_id;
        //
        public static string m_admin_user_id;
        public static string m_admin_vendor_type_id;
        public static string m_admin_vendor_id;
        public static string m_admin_yarn_name_id;
        public static string m_admin_color_id;
        public static string m_admin_yarn_count_id;
        public static string m_admin_unit_id;
        public static string m_admin_design_id;
        public static string m_admin_size_id;
        public static string m_admin_city_id;
        //
        public static bool m_FMTR101_open;
        public static bool m_FMTR102_open;
        public static bool m_FMTR103_open;
        public static bool m_FMTR201_open;
        public static bool m_FMTR202_open;
        public static bool m_FMTR301_open;
        public static bool m_FMTR302_open;
        public static bool m_FMTR303_open;
        public static bool m_FMTR401_open;
        public static bool m_FMTR402_open;
        public static bool m_FMTR501_open;
        public static bool m_FMTR502_open;
        public static bool m_FMTR601_open;
        public static bool m_FMTR602_open;
        public static bool m_FMTR603_open;
        //
        public static bool m_FMAD101_open;
        public static bool m_FMAD102_open;
        public static bool m_FMAD103_open;
        public static bool m_FMAD104_open;
        public static bool m_FMAD105_open;
        public static bool m_FMAD106_open;
        public static bool m_FMAD107_open;
        public static bool m_FMAD108_open;
        public static bool m_FMAD109_open;
        //
        public static bool m_RPTR102_open;
        public static bool m_RPTR103_open;
        public static bool m_RPTR104_open;
        public static bool m_RPTR105_open;
        public static bool m_RPTR131_open;
        public static bool m_RPTR112_open;
        public static bool m_RPTR113_open;
        public static bool m_RPTR114_open;
        public static bool m_RPTR115_open;
        public static bool m_RPTR122_open;
        public static bool m_RPTR123_open;
        public static bool m_RPTR124_open;
        public static bool m_RPTR125_open;
        //
        public static bool m_RPTR202_open;
        public static bool m_RPTR203_open;
        public static bool m_RPTR204_open;
        public static bool m_RPTR205_open;
        public static bool m_RPTR212_open;
        public static bool m_RPTR213_open;
        public static bool m_RPTR214_open;
        public static bool m_RPTR215_open;
        public static bool m_RPTR231_open;
        public static bool m_RPTR232_open;
        //
        public static bool m_RPTR302_open;
        public static bool m_RPTR303_open;
        public static bool m_RPTR304_open;
        public static bool m_RPTR305_open;
        public static bool m_RPTR312_open;
        public static bool m_RPTR313_open;
        public static bool m_RPTR314_open;
        public static bool m_RPTR315_open;
        public static bool m_RPTR322_open;
        public static bool m_RPTR323_open;
        public static bool m_RPTR331_open;
        public static bool m_RPTR332_open;
        public static bool m_RPTR333_open;
        //
        public static bool m_RPTR402_open;
        public static bool m_RPTR403_open;
        public static bool m_RPTR404_open;
        public static bool m_RPTR405_open;
        public static bool m_RPTR412_open;
        public static bool m_RPTR413_open;
        public static bool m_RPTR414_open;
        public static bool m_RPTR415_open;
        public static bool m_RPTR431_open;
        public static bool m_RPTR432_open;
        //
        public static bool m_RPTR502_open;
        public static bool m_RPTR503_open;
        public static bool m_RPTR504_open;
        public static bool m_RPTR505_open;
        public static bool m_RPTR512_open;
        public static bool m_RPTR513_open;
        public static bool m_RPTR514_open;
        public static bool m_RPTR515_open;
        public static bool m_RPTR531_open;
        public static bool m_RPTR532_open;
        //
        public static bool m_RPTR602_open;
        public static bool m_RPTR603_open;
        public static bool m_RPTR604_open;
        //

        public static bool m_read_config_file()
        {
            try
            {
                //<add key="sqlconn" value="Provider=SQLOLEDB;Data Source=HOME;Persist Security Info=True;Password=admin123;User ID=sa;Initial Catalog=tisdb;" />
                //<add key="sql_conn" value="Data Source=HOME;Password=admin123;User ID=sa;Initial Catalog=tisdb;" />
                m_db_provider = @System.Configuration.ConfigurationManager.AppSettings["M_DB_PROVIDER"].ToString();
                m_db_server = @System.Configuration.ConfigurationManager.AppSettings["M_DB_SERVER"].ToString();
                m_db_name = @System.Configuration.ConfigurationManager.AppSettings["M_DB_NAME"].ToString();
                m_db_user = @System.Configuration.ConfigurationManager.AppSettings["M_DB_USER"].ToString();
                m_db_password = @System.Configuration.ConfigurationManager.AppSettings["M_DB_PASSWORD"].ToString();
                PCREP.m_local_report_path = @System.Configuration.ConfigurationManager.AppSettings["M_REPORT_FILES_PATH"].ToString();
                m_oledb_connection = "Provider=" + m_db_provider.ToString() + ";Data Source=" + m_db_server.ToString() + ";Persist Security Info=True;Password=" + m_db_password.ToString() + ";User ID=" + m_db_user.ToString() + ";Initial Catalog=" + m_db_name.ToString() + ";";
                m_sqldb_connection = "Data Source=" + m_db_server.ToString() + ";Password=" + m_db_password.ToString() + ";User ID=" + m_db_user.ToString() + ";Initial Catalog=" + m_db_name.ToString() + ";";
                m_tran_date = m_get_date();
                //
                return true;
            }
            catch (Exception ex)
            {
                PCMSG.ShowError(ex);
                return false;
            }
        }

        public static bool m_read_config_data()
        {
            try
            {
                mc_app_product = m_get_config_value("APP_PRODUCT");
                mc_app_version = m_get_config_value("APP_VERSION");
                mc_app_build = m_get_config_value("APP_BUILD");
                //
                mc_lic_key = m_get_config_value("LIC_KEY");
                mc_lic_from = m_get_config_value("LIC_FROM");
                mc_lic_upto = m_get_config_value("LIC_UPTO");
                mc_lic_cals = m_get_config_value("LIC_CALS");
                //
                mc_org_name = m_get_config_value("ORG_NAME");
                mc_org_address1 = m_get_config_value("ORG_ADDRESS1");
                mc_org_address2 = m_get_config_value("ORG_ADDRESS2");
                mc_org_address3 = m_get_config_value("ORG_ADDRESS3");
                mc_org_city = m_get_config_value("ORG_CITY");
                mc_org_state = m_get_config_value("ORG_STATE");
                mc_org_country = m_get_config_value("ORG_COUNTRY");
                mc_org_pincode = m_get_config_value("ORG_PINCODE");
                mc_org_email = m_get_config_value("ORG_EMAIL");
                mc_org_fax = m_get_config_value("ORG_FAX");
                mc_org_mobile1 = m_get_config_value("ORG_MOBILE1");
                mc_org_mobile2 = m_get_config_value("ORG_MOBILE2");
                mc_org_phone1 = m_get_config_value("ORG_PHONE1");
                mc_org_phone2 = m_get_config_value("ORG_PHONE2");
                mc_org_website = m_get_config_value("ORG_WEBSITE");
                return true;
            }
            catch (Exception ex)
            {
                PCMSG.ShowError(ex);
                return false;
            }
        }

        public static bool m_verify_version()
        {
            try
            {
                if (mc_app_product != Properties.Resources.APP_PRODUCT.ToString())
                {
                    return false;
                }
                else if(mc_app_version != Properties.Resources.APP_VERSION.ToString())
                {
                    return false;
                }
                else if(mc_app_build != Properties.Resources.APP_BUILD.ToString())
                {
                    return false;
                }
                return true;
            }
            catch (Exception ex)
            {
                PCMSG.ShowError(ex);
                return false;
            }
        }

        public static bool m_verify_license()
        {
            try
            {
                if(mc_lic_key != Properties.Resources.LIC_HASH_KEY.ToString())
                {
                    return false;
                }
                return true;
            }
            catch (Exception ex)
            {
                PCMSG.ShowError(ex);
                return false;
            }
        }

        public static string m_get_next_sequence(string p_sequence_id)
        {
            String strQuery = String.Empty;
            OleDbConnection sqlConn = new OleDbConnection();
            OleDbCommand sqlComm = new OleDbCommand();
            OleDbDataReader sqlRead;// = new OleDbDataReader();
            String strReturn = String.Empty;
            int sequence_value = 0;
            int sequence_minimum = 0;
            int sequence_maximum = 0;
            String sequence_prefix = String.Empty;
            String sequence_suffix = String.Empty;
            String sequence_format = String.Empty;
            String sequence_reset = String.Empty;
            String sequence_id = String.Empty;

            //           
            sqlConn.ConnectionString = PCPUB.m_oledb_connection.ToString();
            sqlConn.Open();
            //
            strQuery = String.Empty;
            strQuery += "update tis_sequence";
            strQuery += " set sequence_value = sequence_value + 1";
            strQuery += " where sequence_id = '" + p_sequence_id + "'";
            sqlComm.Connection = sqlConn;
            sqlComm.CommandText = strQuery.ToString();
            sqlComm.ExecuteNonQuery();
            //
            strQuery = String.Empty;
            strQuery += "select isnull(sequence_value,0) sequence_value ,isnull(sequence_minimum,0) sequence_minimum, isnull(sequence_maximum,0) sequence_maximum,";
            strQuery += "isnull(sequence_prefix,'') sequence_prefix,isnull(sequence_suffix,'') sequence_suffix, isnull(sequence_format,'') sequence_format,";
            strQuery += "isnull(sequence_reset,'') sequence_reset";
            strQuery += " from tis_sequence";
            strQuery += " where sequence_id = '" + p_sequence_id + "'";
            //
            sqlComm = new OleDbCommand();
            sqlComm.Connection = sqlConn;
            sqlComm.CommandText = strQuery.ToString();
            sqlRead = sqlComm.ExecuteReader();
            int tmp = 0;
            if (sqlRead.Read())
            {
                try
                {
                    sequence_value = int.Parse(sqlRead["sequence_value"].ToString());
                    sequence_minimum = int.Parse(sqlRead["sequence_minimum"].ToString());
                    sequence_maximum = int.Parse(sqlRead["sequence_maximum"].ToString());
                    sequence_prefix = sqlRead["sequence_prefix"].ToString().Trim().ToUpper();
                    sequence_suffix = sqlRead["sequence_suffix"].ToString().Trim().ToUpper();
                    sequence_format = sqlRead["sequence_format"].ToString().Trim().ToUpper();
                    sequence_reset = sqlRead["sequence_reset"].ToString().Trim().ToUpper();
                    sqlRead.Close();
                    sqlRead.Dispose();
                    //
                    if (sequence_value < sequence_minimum)
                    {
                        sequence_value = sequence_minimum;
                    }
                    if (sequence_value > sequence_maximum)
                    {
                        sequence_value = sequence_minimum;
                    }
                    if (sequence_value == sequence_minimum)
                    {
                        strQuery = String.Empty;
                        strQuery += "update tis_sequence";
                        strQuery += " set sequence_value = " + sequence_value.ToString();
                        strQuery += " where sequence_id = '" + p_sequence_id + "'";
                        sqlComm = new OleDbCommand();
                        sqlComm.Connection = sqlConn;
                        sqlComm.CommandText = strQuery.ToString();
                        sqlComm.ExecuteNonQuery();
                    }
                    if (sequence_prefix.Length > 0)
                    {
                        tmp = int.Parse(sequence_format.Substring(1, 1));
                        if (tmp > 0)
                            sequence_prefix = sequence_prefix.Substring(0, tmp).Trim();
                    }
                    tmp = 0;
                    if (sequence_suffix.Length > 0)
                    {
                        tmp = int.Parse(sequence_format.Substring(5, 1));
                        if (tmp > 0)
                            sequence_suffix = sequence_suffix.Substring(0, tmp).Trim();
                    }
                    sequence_id = sequence_value.ToString().Trim();
                    tmp = 0;
                    tmp = int.Parse(sequence_format.Substring(3, 1));
                    if (tmp > 0)
                    {
                        sequence_id = sequence_id.PadLeft(tmp, '0');
                    }
                    sequence_id = sequence_prefix + sequence_id + sequence_suffix;
                    strReturn = sequence_id;
                }
                catch (Exception e)
                {
                    PCMSG.Show(e.Message);
                }
            }
            //
            sqlRead.Close();
            sqlRead.Dispose();
            sqlComm.Dispose();
            sqlConn.Close();
            sqlConn.Dispose();
            //
            return strReturn;
        }

        public static string m_get_next_sequence(string p_sequence_id, DateTimePicker p_datetime)
        {
            String strQuery = String.Empty;
            OleDbConnection sqlConn = new OleDbConnection();
            OleDbCommand sqlComm = new OleDbCommand();
            OleDbDataReader sqlRead;// = new OleDbDataReader();
            String strReturn = String.Empty;
            int sequence_value = 0;
            int sequence_minimum = 0;
            int sequence_maximum = 0;
            String sequence_prefix = String.Empty;
            String sequence_suffix = String.Empty;
            String sequence_format = String.Empty;
            String sequence_reset = String.Empty;
            String sequence_id = String.Empty;
            String sequence_date = String.Empty;
            int sequence_id_count = 0;
            String sequence_mmdd = String.Empty;
            //
            sequence_date = m_get_sql_date(p_datetime).ToString();
            sequence_mmdd = p_datetime.Value.Month.ToString("0#") + p_datetime.Value.Day.ToString("0#");
            sequence_id = p_sequence_id.ToString();
            //           
            sqlConn.ConnectionString = PCPUB.m_oledb_connection.ToString();
            sqlConn.Open();
            //
            strQuery = String.Empty;
            strQuery += "select isnull(sequence_value,0) sequence_value ,isnull(sequence_minimum,0) sequence_minimum, isnull(sequence_maximum,0) sequence_maximum,";
            strQuery += "isnull(sequence_prefix,'') sequence_prefix,isnull(sequence_suffix,'') sequence_suffix, isnull(sequence_format,'') sequence_format,";
            strQuery += "isnull(sequence_reset,'') sequence_reset";
            strQuery += " from tis_sequence";
            strQuery += " where sequence_id = '" + p_sequence_id + "'";
            sqlComm = new OleDbCommand();
            sqlComm.Connection = sqlConn;
            sqlComm.CommandText = strQuery.ToString();
            sqlRead = sqlComm.ExecuteReader();
            int tmp = 0;
            if (sqlRead.Read())
            {
                sequence_value = int.Parse(sqlRead["sequence_value"].ToString());
                sequence_minimum = int.Parse(sqlRead["sequence_minimum"].ToString());
                sequence_maximum = int.Parse(sqlRead["sequence_maximum"].ToString());
                sequence_prefix = sqlRead["sequence_prefix"].ToString().Trim().ToUpper();
                sequence_suffix = sqlRead["sequence_suffix"].ToString().Trim().ToUpper();
                sequence_format = sqlRead["sequence_format"].ToString().Trim().ToUpper();
                sequence_reset = sqlRead["sequence_reset"].ToString().Trim().ToUpper();
                sqlRead.Close();
            }
            //
            strQuery = String.Empty;
            strQuery += " SELECT COUNT(1) sequence_id_count";
            strQuery += " FROM tis_sequence_date";
            strQuery += " WHERE sequence_date = '" + sequence_date + "'";
            strQuery += " AND sequence_id = '" + sequence_id + "'";
            sqlComm = new OleDbCommand();
            sqlComm.Connection = sqlConn;
            sqlComm.CommandText = strQuery.ToString();
            sqlRead = sqlComm.ExecuteReader();
            if (sqlRead.Read())
            {
                sequence_id_count = int.Parse(sqlRead["sequence_id_count"].ToString());
            }
            sqlRead.Close();
            //sqlRead.Dispose();
            //
            sequence_value = 0;
            if (sequence_id_count <= 0)
            {
                strQuery = String.Empty;
                strQuery += "INSERT INTO tis_sequence_date ";
                strQuery += " (sequence_date,sequence_id,sequence_value) VALUES (";
                strQuery += "'" + sequence_date + "',";
                strQuery += "'" + sequence_id + "',";
                strQuery += "1)";
                sqlComm = new OleDbCommand();
                sqlComm.Connection = sqlConn;
                sqlComm.CommandText = strQuery.ToString();
                sqlComm.ExecuteNonQuery();
            }
            else
            {
                strQuery = String.Empty;
                strQuery += " UPDATE tis_sequence_date";
                strQuery += " SET sequence_value  = sequence_value + 1";
                strQuery += " WHERE sequence_date = '" + sequence_date + "'";
                strQuery += " AND sequence_id = '" + sequence_id + "'";
                sqlComm = new OleDbCommand();
                sqlComm.Connection = sqlConn;
                sqlComm.CommandText = strQuery.ToString();
                sqlComm.ExecuteNonQuery();
            }
            //
            strQuery = String.Empty;
            strQuery += " SELECT ISNULL(sequence_value,0) sequence_value";
            strQuery += " FROM tis_sequence_date";
            strQuery += " WHERE sequence_date = '" + sequence_date + "'";
            strQuery += " AND sequence_id = '" + sequence_id + "'";
            sqlComm = new OleDbCommand();
            sqlComm.Connection = sqlConn;
            sqlComm.CommandText = strQuery.ToString();
            sqlRead = sqlComm.ExecuteReader();
            if (sqlRead.Read())
            {
                sequence_value = int.Parse(sqlRead["sequence_value"].ToString());
            }
            sqlRead.Close();
            //
            if (sequence_value < sequence_minimum)
            {
                sequence_value = sequence_minimum;
            }
            if (sequence_value > sequence_maximum)
            {
                sequence_value = sequence_minimum;
            }
            if (sequence_value == sequence_minimum)
            {
                strQuery = String.Empty;
                strQuery += " UPDATE tis_sequence_date";
                strQuery += " SET sequence_value  = " + sequence_minimum.ToString();
                strQuery += " WHERE sequence_id = '" + sequence_id + "'";
                strQuery += " AND sequence_date = '" + sequence_date + "'";
                sqlComm = new OleDbCommand();
                sqlComm.Connection = sqlConn;
                sqlComm.CommandText = strQuery.ToString();
                sqlComm.ExecuteNonQuery();
            }
            if (sequence_prefix.Length > 0)
            {
                tmp = int.Parse(sequence_format.Substring(1, 1));
                if (tmp > 0)
                    sequence_prefix = sequence_prefix.Substring(0, tmp).Trim();
            }
            tmp = 0;
            if (sequence_suffix.Length > 0)
            {
                tmp = int.Parse(sequence_format.Substring(5, 1));
                if (tmp > 0)
                    sequence_suffix = sequence_suffix.Substring(0, tmp).Trim();
            }
            sequence_id = sequence_value.ToString().Trim();
            tmp = 0;
            tmp = int.Parse(sequence_format.Substring(3, 1));
            if (tmp > 0)
            {
                sequence_id = sequence_id.PadLeft(tmp, '0');
            }
            sequence_id = sequence_prefix + sequence_mmdd + sequence_id + sequence_suffix;
            strReturn = sequence_id;
            //
            sqlRead.Close();
            sqlRead.Dispose();
            sqlComm.Dispose();
            sqlConn.Close();
            sqlConn.Dispose();
            //
            return strReturn;
        }

        public static DateTime m_get_date()
        {
            String strQuery = String.Empty;
            OleDbConnection sqlConn = new OleDbConnection();
            OleDbCommand sqlComm = new OleDbCommand();
            OleDbDataReader sqlRead;// = new OleDbDataReader();
            DateTime strReturn = DateTime.Now;
            try
            {
                sqlConn.ConnectionString = PCPUB.m_oledb_connection.ToString();
                sqlConn.Open();
                //
                strQuery = String.Empty;
                strQuery += "SELECT CONVERT(VARCHAR(10),GETDATE(),103) strReturn";
                //
                sqlComm.Connection = sqlConn;
                sqlComm.CommandText = strQuery.ToString();
                sqlRead = sqlComm.ExecuteReader();
                //
                if (sqlRead.Read())
                {
                    strReturn = DateTime.Parse(sqlRead["strReturn"].ToString());
                }
                //
                sqlRead.Close();
                sqlConn.Close();
                sqlRead.Dispose();
                sqlComm.Dispose();
                sqlConn.Dispose();
                //
            }
            catch (Exception e)
            {
                PCMSG.ShowError(e);
            }
            return strReturn;

        }

        public static string m_get_sql_date()
        {
            String strQuery = String.Empty;
            OleDbConnection sqlConn = new OleDbConnection();
            OleDbCommand sqlComm = new OleDbCommand();
            OleDbDataReader sqlRead;// = new OleDbDataReader();
            string strReturn = string.Empty;
            //           
            sqlConn.ConnectionString = PCPUB.m_oledb_connection.ToString();
            sqlConn.Open();
            //
            strQuery = String.Empty;
            strQuery += "select convert(varchar(10),getdate(),121) strReturn";
            //
            sqlComm.Connection = sqlConn;
            sqlComm.CommandText = strQuery.ToString();
            sqlRead = sqlComm.ExecuteReader();
            //
            if (sqlRead.Read())
            {
                strReturn = sqlRead["strReturn"].ToString();
            }
            //
            sqlRead.Close();
            sqlConn.Close();
            sqlRead.Dispose();
            sqlComm.Dispose();
            sqlConn.Dispose();
            //
            return strReturn;
        }

        public static string m_get_sql_date(DateTimePicker p_datetimepicker)
        {
            DateTime datetime_value;
            datetime_value = p_datetimepicker.Value;
            return m_get_sql_date(datetime_value);
        }

        public static string m_get_sql_date(DateTime p_datetime)
        {
            string sYear = String.Empty;
            string sMonth = String.Empty;
            string sDate = String.Empty;
            sYear = p_datetime.Year.ToString("0###");
            sMonth = p_datetime.Month.ToString("0#");
            sDate = p_datetime.Day.ToString("0#");
            string strReturn = sYear + "-" + sMonth + "-" + sDate;
            return strReturn;
        }

        public static string m_get_sql_date(String p_date)
        {
            string sYear = String.Empty;
            string sMonth = String.Empty;
            string sDate = String.Empty;
            sYear = p_date.Substring(6, 4);
            sMonth = p_date.Substring(3, 2);
            sDate = p_date.Substring(0, 2);
            string strReturn = sYear + "-" + sMonth + "-" + sDate;
            return strReturn;
        }

        public static string m_get_sql_datetime()
        {
            String strQuery = String.Empty;
            OleDbConnection sqlConn = new OleDbConnection();
            OleDbCommand sqlComm = new OleDbCommand();
            OleDbDataReader sqlRead;// = new OleDbDataReader();
            string strReturn = string.Empty;
            //           
            sqlConn.ConnectionString = PCPUB.m_oledb_connection.ToString();
            sqlConn.Open();
            //
            strQuery = String.Empty;
            strQuery += "select convert(varchar(19),getdate(),121) strReturn";
            //
            sqlComm.Connection = sqlConn;
            sqlComm.CommandText = strQuery.ToString();
            sqlRead = sqlComm.ExecuteReader();
            //
            if (sqlRead.Read())
            {
                strReturn = sqlRead["strReturn"].ToString();
            }
            //
            sqlRead.Close();
            sqlConn.Close();
            sqlRead.Dispose();
            sqlComm.Dispose();
            sqlConn.Dispose();
            //
            return strReturn;
        }

        private static String get_combo_query(String p_lookup_type)
        {
            String sql_query = String.Empty;
            switch (p_lookup_type)
            {
                case "YARN_VENDOR":
                    sql_query += " SELECT [vendor_id] LOOKUP_CODE,[vendor_name] LOOKUP_TEXT";
                    sql_query += " FROM [tis_vendor] ";
                    sql_query += " WHERE [vendor_type_id] = 'YARN_VEND'";
                    sql_query += " AND [vendor_id] NOT IN ('YARNSTOCK')";
                    sql_query += " ORDER BY [vendor_name]";
                    break;
                case "YARN_BUYER":
                    sql_query += " SELECT [vendor_id] LOOKUP_CODE,[vendor_name] LOOKUP_TEXT";
                    sql_query += " FROM [tis_vendor] ";
                    sql_query += " WHERE [vendor_type_id] = 'YARN_BUYER'";
                    sql_query += " AND [vendor_id] NOT IN ('YARNSTOCK')";
                    sql_query += " ORDER BY [vendor_name]";
                    break;
                case "DYER":
                    sql_query += " SELECT [vendor_id] LOOKUP_CODE,[vendor_name] LOOKUP_TEXT";
                    sql_query += " FROM [tis_vendor] ";
                    sql_query += " WHERE [vendor_type_id] = 'DYER'";
                    sql_query += " ORDER BY [vendor_name]";
                    break;
                case "WEAVER":
                    sql_query += " SELECT [vendor_id] LOOKUP_CODE,[vendor_name] LOOKUP_TEXT";
                    sql_query += " FROM [tis_vendor] ";
                    sql_query += " WHERE [vendor_type_id] = 'WEAVER'";
                    sql_query += " ORDER BY [vendor_name]";
                    break;
                case "TAILOR":
                    sql_query += " SELECT [vendor_id] LOOKUP_CODE,[vendor_name] LOOKUP_TEXT";
                    sql_query += " FROM [tis_vendor] ";
                    sql_query += " WHERE [vendor_type_id] = 'TAILOR'";
                    sql_query += " ORDER BY [vendor_name]";
                    break;
                case "WASHER":
                    sql_query += " SELECT [vendor_id] LOOKUP_CODE,[vendor_name] LOOKUP_TEXT";
                    sql_query += " FROM [tis_vendor] ";
                    sql_query += " WHERE [vendor_type_id] = 'WASHER'";
                    sql_query += " ORDER BY [vendor_name]";
                    break;
                case "TRANSPORT":
                    sql_query += " SELECT [vendor_id] LOOKUP_CODE,[vendor_name] LOOKUP_TEXT";
                    sql_query += " FROM [tis_vendor] ";
                    sql_query += " WHERE [vendor_type_id] = 'TRANSPORT'";
                    sql_query += " ORDER BY [vendor_name]";
                    break;
                case "YARN_NAME":
                    sql_query += " SELECT [yarn_name_id] LOOKUP_CODE,[yarn_name_name] LOOKUP_TEXT";
                    sql_query += " FROM [tis_yarn_name] ";
                    sql_query += " ORDER BY [yarn_name_name]";
                    break;
                case "CITY":
                    sql_query += " SELECT [city_id] LOOKUP_CODE,[city_name] LOOKUP_TEXT";
                    sql_query += " FROM [vw_city] ";
                    sql_query += " ORDER BY [city_name]";
                    break;
                case "YARN_COUNT":
                    sql_query += " SELECT [yarn_count_id] LOOKUP_CODE,[yarn_count_name] LOOKUP_TEXT";
                    sql_query += " FROM [tis_yarn_count] ";
                    sql_query += " ORDER BY [yarn_count_name]";
                    break;
                case "COLOR":
                    sql_query += " SELECT [color_id] LOOKUP_CODE,[color_name] LOOKUP_TEXT";
                    sql_query += " FROM [tis_color] ";
                    sql_query += " ORDER BY [color_name]";
                    break;
                case "UNIT_FMTR101":
                    sql_query += " SELECT [unit_id] LOOKUP_CODE,[unit_name] LOOKUP_TEXT";
                    sql_query += " FROM [vw_unit_vs_form] ";
                    sql_query += " WHERE [form_id] = 'FMTR101'";
                    sql_query += " ORDER BY [unit_name]";
                    break;
                case "UNIT_FMTR102":
                    sql_query += " SELECT [unit_id] LOOKUP_CODE,[unit_name] LOOKUP_TEXT";
                    sql_query += " FROM [vw_unit_vs_form] ";
                    sql_query += " WHERE [form_id] = 'FMTR102'";
                    sql_query += " ORDER BY [unit_name]";
                    break;
                case "UNIT_FMTR103":
                    sql_query += " SELECT [unit_id] LOOKUP_CODE,[unit_name] LOOKUP_TEXT";
                    sql_query += " FROM [vw_unit_vs_form] ";
                    sql_query += " WHERE [form_id] = 'FMTR103'";
                    sql_query += " ORDER BY [unit_name]";
                    break;
                case "UNIT_FMTR201":
                    sql_query += " SELECT [unit_id] LOOKUP_CODE,[unit_name] LOOKUP_TEXT";
                    sql_query += " FROM [vw_unit_vs_form] ";
                    sql_query += " WHERE [form_id] = 'FMTR201'";
                    sql_query += " ORDER BY [unit_name]";
                    break;
                case "UNIT_FMTR202":
                    sql_query += " SELECT [unit_id] LOOKUP_CODE,[unit_name] LOOKUP_TEXT";
                    sql_query += " FROM [vw_unit_vs_form] ";
                    sql_query += " WHERE [form_id] = 'FMTR202'";
                    sql_query += " ORDER BY [unit_name]";
                    break;
                case "UNIT_FMTR301":
                    sql_query += " SELECT [unit_id] LOOKUP_CODE,[unit_name] LOOKUP_TEXT";
                    sql_query += " FROM [vw_unit_vs_form] ";
                    sql_query += " WHERE [form_id] = 'FMTR301'";
                    sql_query += " ORDER BY [unit_name]";
                    break;
                case "UNIT_FMTR302":
                    sql_query += " SELECT [unit_id] LOOKUP_CODE,[unit_name] LOOKUP_TEXT";
                    sql_query += " FROM [vw_unit_vs_form] ";
                    sql_query += " WHERE [form_id] = 'FMTR302'";
                    sql_query += " ORDER BY [unit_name]";
                    break;
                case "UNIT_FMTR303":
                    sql_query += " SELECT [unit_id] LOOKUP_CODE,[unit_name] LOOKUP_TEXT";
                    sql_query += " FROM [vw_unit_vs_form] ";
                    sql_query += " WHERE [form_id] = 'FMTR301'";
                    sql_query += " ORDER BY [unit_name]";
                    break;
                case "UNIT_FMTR401":
                    sql_query += " SELECT [unit_id] LOOKUP_CODE,[unit_name] LOOKUP_TEXT";
                    sql_query += " FROM [vw_unit_vs_form] ";
                    sql_query += " WHERE [form_id] = 'FMTR401'";
                    sql_query += " ORDER BY [unit_name]";
                    break;
                case "UNIT_FMTR402":
                    sql_query += " SELECT [unit_id] LOOKUP_CODE,[unit_name] LOOKUP_TEXT";
                    sql_query += " FROM [vw_unit_vs_form] ";
                    sql_query += " WHERE [form_id] = 'FMTR402'";
                    sql_query += " ORDER BY [unit_name]";
                    break;
                case "UNIT_FMTR501":
                    sql_query += " SELECT [unit_id] LOOKUP_CODE,[unit_name] LOOKUP_TEXT";
                    sql_query += " FROM [vw_unit_vs_form] ";
                    sql_query += " WHERE [form_id] = 'FMTR501'";
                    sql_query += " ORDER BY [unit_name]";
                    break;
                case "UNIT_FMTR502":
                    sql_query += " SELECT [unit_id] LOOKUP_CODE,[unit_name] LOOKUP_TEXT";
                    sql_query += " FROM [vw_unit_vs_form] ";
                    sql_query += " WHERE [form_id] = 'FMTR502'";
                    sql_query += " ORDER BY [unit_name]";
                    break;
                case "UNIT_YARN":
                    sql_query += " SELECT [unit_id] LOOKUP_CODE,[unit_name] LOOKUP_TEXT";
                    sql_query += " FROM [tis_unit] ";
                    sql_query += " WHERE [unit_type_id] = 'YARN'";
                    sql_query += " ORDER BY [unit_name]";
                    break;
                case "UNIT_CLOTH":
                    sql_query += " SELECT [unit_id] LOOKUP_CODE,[unit_name] LOOKUP_TEXT";
                    sql_query += " FROM [tis_unit] ";
                    sql_query += " WHERE [unit_type_id] = 'CLOTH'";
                    sql_query += " ORDER BY [unit_name]";
                    break;
                case "USER_ROLE":
                    sql_query += " SELECT [user_role_id] LOOKUP_CODE,[user_role_name] LOOKUP_TEXT";
                    sql_query += " FROM (SELECT 'ADMIN' [user_role_id] ,'Administrator' [user_role_name] UNION SELECT 'USER' [user_role_id],'Regular User' [user_role_name]) a";
                    sql_query += " ORDER BY [user_role_name]";
                    break;
                case "VENDOR_TYPE":
                    sql_query += " SELECT [vendor_type_id] LOOKUP_CODE,[vendor_type_name] LOOKUP_TEXT";
                    sql_query += " FROM [tis_vendor_type] ";
                    sql_query += " ORDER BY [vendor_type_name]";
                    break;
                case "DESIGN":
                    sql_query += " SELECT [design_id] LOOKUP_CODE,[design_name] LOOKUP_TEXT";
                    sql_query += " FROM [tis_design] ";
                    sql_query += " ORDER BY [design_id]";
                    break;
                case "SIZE":
                    sql_query += " SELECT [size_id] LOOKUP_CODE,[size_name] LOOKUP_TEXT";
                    sql_query += " FROM [tis_size] ";
                    sql_query += " ORDER BY [size_name]";
                    break;
                case "YARN_DELIVERY_FROM":
                    sql_query += " SELECT [vendor_type_id] LOOKUP_CODE,[vendor_type_name] LOOKUP_TEXT";
                    sql_query += " FROM (SELECT 'YARN_STOCK' [vendor_type_id] ,'YARN STOCK' [vendor_type_name] UNION SELECT 'YARN_VENDOR' [vendor_type_id],'YARN VENDOR' [vendor_type_name]) a";
                    sql_query += " ORDER BY [vendor_type_name]";
                    break;
                case "NONE":
                    sql_query = String.Empty;
                    break;
            }
            return sql_query;
        }

        public static void m_fill_combo(ComboBox p_combo, string p_lookup_type)
        {
            String sql_query = String.Empty;
            OleDbConnection sql_conn = new OleDbConnection();
            OleDbCommand sql_comm = new OleDbCommand();
            OleDbDataReader sql_read;
            m_combo_item ci = new m_combo_item();
            //
            p_combo.Items.Clear();
            sql_query = get_combo_query(p_lookup_type);
            if (!sql_query.Equals(String.Empty))
            {
                sql_conn.ConnectionString = PCPUB.m_oledb_connection.ToString();
                sql_conn.Open();
                sql_comm.Connection = sql_conn;
                sql_comm.CommandText = sql_query.ToString();
                sql_read = sql_comm.ExecuteReader();
                //
                while (sql_read.Read())
                {
                    ci = new m_combo_item();
                    ci.combo_code = sql_read["LOOKUP_CODE"].ToString();
                    ci.combo_text = sql_read["LOOKUP_TEXT"].ToString();
                    p_combo.Items.Add(ci);
                    p_combo.DisplayMember = "combo_text";
                    p_combo.ValueMember = "combo_code";
                }
                sql_read.Close();
                sql_read.Dispose();
                sql_conn.Close();
                sql_comm.Dispose();
                sql_conn.Dispose();
            }
        }

        public static void m_fill_combo(DataGridViewComboBoxColumn p_combo, string p_lookup_type)
        {
            String sql_query = String.Empty;
            OleDbConnection sql_conn = new OleDbConnection();
            OleDbCommand sql_comm = new OleDbCommand();
            OleDbDataReader sql_read;
            m_combo_item ci = new m_combo_item();
            //
            p_combo.Items.Clear();
            sql_query = get_combo_query(p_lookup_type);
            if (!sql_query.Equals(String.Empty))
            {
                sql_conn.ConnectionString = PCPUB.m_oledb_connection.ToString();
                sql_conn.Open();
                sql_comm.Connection = sql_conn;
                sql_comm.CommandText = sql_query.ToString();
                sql_read = sql_comm.ExecuteReader();
                //
                while (sql_read.Read())
                {
                    ci = new m_combo_item();
                    ci.combo_code = sql_read["LOOKUP_CODE"].ToString();
                    ci.combo_text = sql_read["LOOKUP_TEXT"].ToString();
                    p_combo.Items.Add(ci);
                    p_combo.DisplayMember = "combo_text";
                    p_combo.ValueMember = "combo_code";
                }
                sql_read.Close();
                sql_read.Dispose();
                sql_comm.Dispose();
                sql_conn.Close();
                sql_conn.Dispose();
            }
        }

        public static String m_get_yarn_vendor_name(String p_id)
        {
            String str_query = String.Empty;
            String str_return = String.Empty;
            OleDbConnection sql_conn = new OleDbConnection();
            OleDbCommand sql_comm = new OleDbCommand();
            OleDbDataReader sql_read;
            //
            str_query = String.Empty;
            str_query += " SELECT [vendor_name] out_name";
            str_query += " FROM [tis_vendor] ";
            str_query += " WHERE [vendor_type_id] = 'YARN_VEND'";
            str_query += " AND [vendor_id] = '" + p_id + "'";
            sql_conn.ConnectionString = PCPUB.m_oledb_connection.ToString();
            sql_conn.Open();
            sql_comm.Connection = sql_conn;
            sql_comm.CommandText = str_query.ToString();
            sql_read = sql_comm.ExecuteReader();
            if (sql_read.Read())
            {
                str_return = sql_read["out_name"].ToString();
            }
            sql_read.Close();
            sql_conn.Close();
            return str_return;
        }

        public static String m_get_yarn_buyer_name(String p_id)
        {
            String str_query = String.Empty;
            String str_return = String.Empty;
            OleDbConnection sql_conn = new OleDbConnection();
            OleDbCommand sql_comm = new OleDbCommand();
            OleDbDataReader sql_read;
            //
            str_query = String.Empty;
            str_query += " SELECT [vendor_name] out_name";
            str_query += " FROM [tis_vendor] ";
            str_query += " WHERE [vendor_type_id] = 'YARN_BUYER'";
            str_query += " AND [vendor_id] = '" + p_id + "'";
            sql_conn.ConnectionString = PCPUB.m_oledb_connection.ToString();
            sql_conn.Open();
            sql_comm.Connection = sql_conn;
            sql_comm.CommandText = str_query.ToString();
            sql_read = sql_comm.ExecuteReader();
            if (sql_read.Read())
            {
                str_return = sql_read["out_name"].ToString();
            }
            sql_read.Close();
            sql_conn.Close();
            return str_return;
        }

        public static String m_get_transport_name(String p_id)
        {
            String str_query = String.Empty;
            String str_return = String.Empty;
            OleDbConnection sql_conn = new OleDbConnection();
            OleDbCommand sql_comm = new OleDbCommand();
            OleDbDataReader sql_read;
            //
            str_query = String.Empty;
            str_query += " SELECT [vendor_name] out_name";
            str_query += " FROM [tis_vendor] ";
            str_query += " WHERE [vendor_type_id] = 'TRANSPORT'";
            str_query += " AND [vendor_id] = '" + p_id + "'";
            sql_conn.ConnectionString = PCPUB.m_oledb_connection.ToString();
            sql_conn.Open();
            sql_comm.Connection = sql_conn;
            sql_comm.CommandText = str_query.ToString();
            sql_read = sql_comm.ExecuteReader();
            if (sql_read.Read())
            {
                str_return = sql_read["out_name"].ToString();
            }
            sql_read.Close();
            sql_conn.Close();
            return str_return;
        }

        public static String m_get_dyer_name(String p_id)
        {
            String str_query = String.Empty;
            String str_return = String.Empty;
            OleDbConnection sql_conn = new OleDbConnection();
            OleDbCommand sql_comm = new OleDbCommand();
            OleDbDataReader sql_read;
            //
            str_query = String.Empty;
            str_query += " SELECT [vendor_name] out_name";
            str_query += " FROM [tis_vendor] ";
            str_query += " WHERE [vendor_type_id] = 'DYER'";
            str_query += " AND [vendor_id] = '" + p_id + "'";
            sql_conn.ConnectionString = PCPUB.m_oledb_connection.ToString();
            sql_conn.Open();
            sql_comm.Connection = sql_conn;
            sql_comm.CommandText = str_query.ToString();
            sql_read = sql_comm.ExecuteReader();
            if (sql_read.Read())
            {
                str_return = sql_read["out_name"].ToString();
            }
            sql_read.Close();
            sql_conn.Close();
            return str_return;
        }

        public static String m_get_weaver_name(String p_id)
        {
            String str_query = String.Empty;
            String str_return = String.Empty;
            OleDbConnection sql_conn = new OleDbConnection();
            OleDbCommand sql_comm = new OleDbCommand();
            OleDbDataReader sql_read;
            //
            str_query = String.Empty;
            str_query += " SELECT [vendor_name] out_name";
            str_query += " FROM [tis_vendor] ";
            str_query += " WHERE [vendor_type_id] = 'WEAVER'";
            str_query += " AND [vendor_id] = '" + p_id + "'";
            sql_conn.ConnectionString = PCPUB.m_oledb_connection.ToString();
            sql_conn.Open();
            sql_comm.Connection = sql_conn;
            sql_comm.CommandText = str_query.ToString();
            sql_read = sql_comm.ExecuteReader();
            if (sql_read.Read())
            {
                str_return = sql_read["out_name"].ToString();
            }
            sql_read.Close();
            sql_conn.Close();
            return str_return;
        }

        public static String m_get_tailor_name(String p_id)
        {
            String str_query = String.Empty;
            String str_return = String.Empty;
            OleDbConnection sql_conn = new OleDbConnection();
            OleDbCommand sql_comm = new OleDbCommand();
            OleDbDataReader sql_read;
            //
            str_query = String.Empty;
            str_query += " SELECT [vendor_name] out_name";
            str_query += " FROM [tis_vendor] ";
            str_query += " WHERE [vendor_type_id] = 'TAILOR'";
            str_query += " AND [vendor_id] = '" + p_id + "'";
            sql_conn.ConnectionString = PCPUB.m_oledb_connection.ToString();
            sql_conn.Open();
            sql_comm.Connection = sql_conn;
            sql_comm.CommandText = str_query.ToString();
            sql_read = sql_comm.ExecuteReader();
            if (sql_read.Read())
            {
                str_return = sql_read["out_name"].ToString();
            }
            sql_read.Close();
            sql_conn.Close();
            return str_return;
        }

        public static String m_get_washer_name(String p_id)
        {
            String str_query = String.Empty;
            String str_return = String.Empty;
            OleDbConnection sql_conn = new OleDbConnection();
            OleDbCommand sql_comm = new OleDbCommand();
            OleDbDataReader sql_read;
            //
            str_query = String.Empty;
            str_query += " SELECT [vendor_name] out_name";
            str_query += " FROM [tis_vendor] ";
            str_query += " WHERE [vendor_type_id] = 'WASHER'";
            str_query += " AND [vendor_id] = '" + p_id + "'";
            sql_conn.ConnectionString = PCPUB.m_oledb_connection.ToString();
            sql_conn.Open();
            sql_comm.Connection = sql_conn;
            sql_comm.CommandText = str_query.ToString();
            sql_read = sql_comm.ExecuteReader();
            if (sql_read.Read())
            {
                str_return = sql_read["out_name"].ToString();
            }
            sql_read.Close();
            sql_conn.Close();
            return str_return;
        }

        public static String m_get_vendor_name(String p_id, String p_type)
        {
            String str_query = String.Empty;
            String str_return = String.Empty;
            OleDbConnection sql_conn = new OleDbConnection();
            OleDbCommand sql_comm = new OleDbCommand();
            OleDbDataReader sql_read;
            //
            str_query = String.Empty;
            str_query += " SELECT [vendor_name] out_name";
            str_query += " FROM [tis_vendor] ";
            str_query += " WHERE [vendor_type_id] = '" + p_type + "'";
            str_query += " AND [vendor_id] = '" + p_id + "'";
            sql_conn.ConnectionString = PCPUB.m_oledb_connection.ToString();
            sql_conn.Open();
            sql_comm.Connection = sql_conn;
            sql_comm.CommandText = str_query.ToString();
            sql_read = sql_comm.ExecuteReader();
            if (sql_read.Read())
            {
                str_return = sql_read["out_name"].ToString();
            }
            sql_read.Close();
            sql_conn.Close();
            return str_return;
        }

        public static String m_get_vendor_type_name(String p_id)
        {
            String str_query = String.Empty;
            String str_return = String.Empty;
            OleDbConnection sql_conn = new OleDbConnection();
            OleDbCommand sql_comm = new OleDbCommand();
            OleDbDataReader sql_read;
            //
            str_query = String.Empty;
            str_query += " SELECT [vendor_type_name] out_name";
            str_query += " FROM [tis_vendor_type] ";
            str_query += " WHERE [vendor_type_id] = '" + p_id + "'";
            sql_conn.ConnectionString = PCPUB.m_oledb_connection.ToString();
            sql_conn.Open();
            sql_comm.Connection = sql_conn;
            sql_comm.CommandText = str_query.ToString();
            sql_read = sql_comm.ExecuteReader();
            if (sql_read.Read())
            {
                str_return = sql_read["out_name"].ToString();
            }
            sql_read.Close();
            sql_conn.Close();
            return str_return;
        }

        public static String m_city_name(String p_id)
        {
            String str_query = String.Empty;
            String str_return = String.Empty;
            OleDbConnection sql_conn = new OleDbConnection();
            OleDbCommand sql_comm = new OleDbCommand();
            OleDbDataReader sql_read;
            //
            str_query = String.Empty;
            str_query += " SELECT [city_name] out_name";
            str_query += " FROM [vw_city] ";
            str_query += " WHERE [city_id] = '" + p_id + "'";
            sql_conn.ConnectionString = PCPUB.m_oledb_connection.ToString();
            sql_conn.Open();
            sql_comm.Connection = sql_conn;
            sql_comm.CommandText = str_query.ToString();
            sql_read = sql_comm.ExecuteReader();
            if (sql_read.Read())
            {
                str_return = sql_read["out_name"].ToString();
            }
            sql_read.Close();
            sql_conn.Close();
            return str_return;
        }

        public static String m_get_config_value(String p_id)
        {
            String str_query = String.Empty;
            String str_return = String.Empty;
            OleDbConnection sql_conn = new OleDbConnection();
            OleDbCommand sql_comm = new OleDbCommand();
            OleDbDataReader sql_read;
            //
            str_query = String.Empty;
            str_query += " SELECT [config_value] out_name";
            str_query += " FROM [tis_config] ";
            str_query += " WHERE [config_key] = '" + p_id + "'";
            sql_conn.ConnectionString = PCPUB.m_oledb_connection.ToString();
            sql_conn.Open();
            sql_comm.Connection = sql_conn;
            sql_comm.CommandText = str_query.ToString();
            sql_read = sql_comm.ExecuteReader();
            if (sql_read.Read())
            {
                str_return = sql_read["out_name"].ToString();
            }
            sql_read.Close();
            sql_conn.Close();
            return str_return;
        }

        public static String m_get_sql_date_string(String pString)
        {
            String DD;
            String MM;
            String YY;
            String oString;
            try
            {
                DD = pString.Substring(0, 2);
                MM = pString.Substring(3, 2);
                YY = pString.Substring(6, 4);
                oString = YY + "-" + MM + "-" + DD;
                return oString;
            }
            catch
            {
                return String.Empty;
            }
        }
        
        // user

        public static String m_get_user_role_id(String p_id)
        {
            String str_query = String.Empty;
            String str_return = String.Empty;
            OleDbConnection sql_conn = new OleDbConnection();
            OleDbCommand sql_comm = new OleDbCommand();
            OleDbDataReader sql_read;
            //
            str_query = String.Empty;
            str_query += " SELECT [user_role_id] out_name";
            str_query += " FROM [tis_user] a";
            str_query += " WHERE [user_id] = '" + p_id + "'";
            sql_conn.ConnectionString = PCPUB.m_oledb_connection.ToString();
            sql_conn.Open();
            sql_comm.Connection = sql_conn;
            sql_comm.CommandText = str_query.ToString();
            sql_read = sql_comm.ExecuteReader();
            if (sql_read.Read())
            {
                str_return = sql_read["out_name"].ToString();
            }
            sql_read.Close();
            sql_conn.Close();
            return str_return;
        }

        public static String m_get_user_role_name(String p_id)
        {
            String str_query = String.Empty;
            String str_return = String.Empty;
            OleDbConnection sql_conn = new OleDbConnection();
            OleDbCommand sql_comm = new OleDbCommand();
            OleDbDataReader sql_read;
            //
            str_query = String.Empty;
            str_query += " SELECT [user_role_name] out_name";
            str_query += " FROM (SELECT 'ADMIN' [user_role_id] ,'Administrator' [user_role_name] UNION SELECT 'USER' [user_role_id],'Regular User' [user_role_name]) a";
            str_query += " WHERE [user_role_id] = '" + p_id + "'";
            sql_conn.ConnectionString = PCPUB.m_oledb_connection.ToString();
            sql_conn.Open();
            sql_comm.Connection = sql_conn;
            sql_comm.CommandText = str_query.ToString();
            sql_read = sql_comm.ExecuteReader();
            if (sql_read.Read())
            {
                str_return = sql_read["out_name"].ToString();
            }
            sql_read.Close();
            sql_conn.Close();
            return str_return;
        }


    }

}
